package com.czy.util.json;

import com.czy.convert.Converter;
import com.czy.util.StringUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class SerializerBool2Int extends JsonSerializer<Boolean> implements Converter<Boolean, Integer> {
    @Override
    public void serialize(Boolean value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeNumber(convert(value));
    }

    @Override
    public Integer convert(Boolean source) {
        return StringUtil.getInt(source);
    }
}
